package try_java;

import java.text.DateFormatSymbols;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

public class class_01 {
    public static void main (String [] args) {
        Date d1 = new Date();
        System.out.println(d1.toString());
        GregorianCalendar d2 = new GregorianCalendar();
        System.out.println(d2.toString());
        int date = d2.get(Calendar.MONTH);
        System.out.printf("data is %d\n", date);
        d2.add(Calendar.MONTH, 2);
        d1 = d2.getTime();
        System.out.println(d1.toString());
        d2 = new GregorianCalendar();
        d1 = d2.getTime();
        System.out.println(d1.toString());
        int today = d2.get(Calendar.DAY_OF_MONTH);
        today -= 10;
        int month = d2.get(Calendar.MONTH);
        d2.set(Calendar.DAY_OF_MONTH, 1);
        int weekday = d2.get(Calendar.DAY_OF_WEEK);
        int firstDayOfWeek = d2.getFirstDayOfWeek();
//        System.out.printf("today is %d\n", today);
//        System.out.printf("month is %d\n", month);
        System.out.printf("weekday is %d\n", weekday);
        System.out.printf("firstDayOfWeek is %d\n", firstDayOfWeek);
        int indent = 0;
        while (weekday != firstDayOfWeek) {
            indent++;
            d2.add(Calendar.DAY_OF_MONTH, -1);
            weekday = d2.get(Calendar.DAY_OF_WEEK);
        }
        String [] weekDayName = new DateFormatSymbols().getShortWeekdays();
//        System.out.print("|");
        do {
            System.out.printf("%6s", weekDayName[weekday]);
            d2.add(Calendar.DAY_OF_MONTH, 1);
            weekday = d2.get(Calendar.DAY_OF_WEEK);
        }
        while(weekday != firstDayOfWeek);
        System.out.println();
        d2.set(Calendar.DAY_OF_MONTH, 1);
        while(indent > 0) {
            System.out.printf("%7s", " ");
            indent--;
        }
        
        while(d2.get(Calendar.MONTH) == month) {
            int currentDay = d2.get(Calendar.DAY_OF_MONTH);
            System.out.printf("%6s", d2.get(Calendar.DAY_OF_MONTH));
            if (currentDay == today) {
                System.out.print("*");
            }
            else {
                System.out.print(" ");
            }
            d2.add(Calendar.DAY_OF_MONTH, 1);
            weekday = d2.get(Calendar.DAY_OF_WEEK);
            if (weekday == firstDayOfWeek) {
                System.out.println();
            }
        }
    }
}
